 bondscell_results $e4d0ad7b-9e72-45c7-9eb9-0ed06567aef8queued¤logsrunning¦outputbody6.2mimetext/plainrootassigneelast_run_timestampA=persist_js_state·has_pluto_hook_features§cell_id$e4d0ad7b-9e72-45c7-9eb9-0ed06567aef8depends_on_disabled_cells§runtime7ڵpublished_object_keysdepends_on_skipped_cells§errored$470eaa98-4073-11eb-349d-e9c34e5478c2queued¤logsrunning¦outputbodyA JuMP Model
Maximization problem with:
Variables: 2
Objective function type: AffExpr
`JuMP.AffExpr`-in-`MathOptInterface.LessThan{Float64}`: 1 constraint
`JuMP.VariableRef`-in-`MathOptInterface.GreaterThan{Float64}`: 2 constraints
`JuMP.VariableRef`-in-`MathOptInterface.LessThan{Float64}`: 2 constraints
Model mode: AUTOMATIC
CachingOptimizer state: EMPTY_OPTIMIZER
Solver name: GLPK
Names registered in the model: con, x, ymimetext/plainrootassigneelast_run_timestampAzpersist_js_state·has_pluto_hook_features§cell_id$470eaa98-4073-11eb-349d-e9c34e5478c2depends_on_disabled_cells§runtime   [Spublished_object_keysdepends_on_skipped_cells§errored$9b4e18a3-669f-4bab-8c22-565428ebf299queued¤logsrunning¦outputbody)opacity (generic function with 2 methods)mimetext/plainrootassigneelast_run_timestampAqapersist_js_state·has_pluto_hook_features§cell_id$9b4e18a3-669f-4bab-8c22-565428ebf299depends_on_disabled_cells§runtime µpublished_object_keysdepends_on_skipped_cells§errored$cdda279d-60bf-495c-b796-a62e5dd1d699queued¤logsrunning¦outputbody(opacity (generic function with 1 method)mimetext/plainrootassigneelast_run_timestampAqrҰpersist_js_state·has_pluto_hook_features§cell_id$cdda279d-60bf-495c-b796-a62e5dd1d699depends_on_disabled_cells§runtime -upublished_object_keysdepends_on_skipped_cells§errored$8bc3d43a-1460-498b-baa8-fcb9a3338457queued¤logsrunning¦outputbody=<div class="markdown"><p>To access variables from the model that are hidden by a let block, use the alternative syntax:</p>
<p>⛔️ Don&#39;t:</p>
<pre><code class="language-julia">value&#40;y&#41;</code></pre>
<p>✔️ Do:</p>
<pre><code class="language-julia">value&#40;model&#91;:y&#93;&#41;</code></pre>
</div>mimetext/htmlrootassigneelast_run_timestampAEpersist_js_state·has_pluto_hook_features§cell_id$8bc3d43a-1460-498b-baa8-fcb9a3338457depends_on_disabled_cells§runtime >-published_object_keysdepends_on_skipped_cells§errored$ce6d95f3-d745-4215-844c-727c9d90861dqueued¤logsrunning¦outputbodyZ<div class="markdown"><h2>Part 2: secret definitions</h2>
<p>JuMP&#39;s macros create global variables, which are not seen by Pluto. For example, <code>@variable&#40;model, 0 &lt; x &lt; 1&#41;</code> defines a global variable called <code>x</code>, while Pluto thinks that the global variable <code>x</code> was <em>referenced</em>, not assigned.</p>
<p>There are two ways to solve this.</p>
<h3>Part 2a: <code>let</code> block &#40;recommended&#41;</h3>
<p>Place the macros inside a <code>let</code> block, to locally scope any secretly created variables.</p>
<p>⛔️ Don&#39;t:</p>
<pre><code class="language-julia">begin
	model &#61; Model&#40;GLPK.Optimizer&#41;

	@variable&#40;model, 20 &lt; y &lt; 30&#41;
	# global variable y is now defined, but Pluto does not know it

	...
end</code></pre>
<p>✔️ Do:</p>
<pre><code class="language-julia">let
	global model &#61; Model&#40;GLPK.Optimizer&#41;

	@variable&#40;model, 20 &lt; y &lt; 30&#41;
	# locally scoped variable y is now defined. Pluto does not know about it, but since the global scope is unaffected, this is fine

	...
end</code></pre>
</div>mimetext/htmlrootassigneelast_run_timestampA,˰persist_js_state·has_pluto_hook_features§cell_id$ce6d95f3-d745-4215-844c-727c9d90861ddepends_on_disabled_cells§runtime published_object_keysdepends_on_skipped_cells§errored$759c0a90-bb03-456e-bbf6-8bf80b249c07queued¤logsrunning¦outputbody><div class="markdown"><h2>Part 1: model mutations</h2>
<p>Because JuMP&#39;s macros <em>modify</em> a model, it is important the the <strong>model construction is contained in a single cell</strong>. Use a <code>let</code> block &#40;more in Part 2&#41;.</p>
<p>⛔️ Don&#39;t:</p>
<pre><code class="language-julia">model &#61; Model&#40;GLPK.Optimizer&#41;</code></pre>
<pre><code class="language-julia">@variable&#40;model, 20 &lt; y &lt; 30&#41;</code></pre>
<p>✔️ Do:</p>
<pre><code class="language-julia">let
	global model &#61; Model&#40;GLPK.Optimizer&#41;

	@variable&#40;model, 20 &lt; y &lt; 30&#41;

	...
end</code></pre>
<h4>optimize&#33;</h4>
<p>Similarly, <code>optimize&#33;</code> will <em>modify</em> the model, so I recommend calling it in the same cell as the model construction.</p>
<p>If, for the purpose of a narrative, you need the optimization to happen in a different cell, then use a &quot;new state, new name&quot; trick:</p>
<pre><code class="language-julia">begin
	optimize&#33;&#40;model&#41;
	model_optimized &#61; model
end</code></pre>
<p>In other cells, reference <code>model_optimized</code> to access <code>model</code> to guarantee that the model optimization has already happened:</p>
<pre><code class="language-julia"># in other cells
value&#40;model_optimized&#91;:x&#93;&#41;</code></pre>
</div>mimetext/htmlrootassigneelast_run_timestampAkpersist_js_state·has_pluto_hook_features§cell_id$759c0a90-bb03-456e-bbf6-8bf80b249c07depends_on_disabled_cells§runtime 	%published_object_keysdepends_on_skipped_cells§errored$69a565bc-e250-4105-9b6b-3b9879dcb417queued¤logsrunning¦outputbody"OPTIMAL::TerminationStatusCode = 1mimetext/plainrootassigneelast_run_timestampA*=:persist_js_state·has_pluto_hook_features§cell_id$69a565bc-e250-4105-9b6b-3b9879dcb417depends_on_disabled_cells§runtimeJ4published_object_keysdepends_on_skipped_cells§errored$95e0721d-321f-478c-8d02-0ac070008a5bqueued¤logsrunning¦outputbodyA JuMP Model
Maximization problem with:
Variables: 2
Objective function type: AffExpr
`JuMP.AffExpr`-in-`MathOptInterface.LessThan{Float64}`: 1 constraint
`JuMP.VariableRef`-in-`MathOptInterface.GreaterThan{Float64}`: 2 constraints
`JuMP.VariableRef`-in-`MathOptInterface.LessThan{Float64}`: 2 constraints
Model mode: AUTOMATIC
CachingOptimizer state: ATTACHED_OPTIMIZER
Solver name: GLPK
Names registered in the model: con, x, ymimetext/plainrootassigneemodel_optlast_run_timestampA@persist_js_state·has_pluto_hook_features§cell_id$95e0721d-321f-478c-8d02-0ac070008a5bdepends_on_disabled_cells§runtime   (|0published_object_keysdepends_on_skipped_cells§errored$d5b9c438-b1e7-4417-870f-afdfc4ee7672queued¤logsrunning¦outputbodyG<div class="markdown"><h1>How to use JuMP in Pluto?</h1>
<p>JuMP uses macros to form a domain-specific language. That is very cool&#33; but unfortunately, Pluto has trouble understanding code with macros. This is a difficult problem that we currently working on, and it is getting closer to being fixed&#33;</p>
<p>For any cell, it is important that Pluto correctly understands which variables are <strong>referenced</strong> and which are <strong>defined</strong>. Pluto&#39;s runtime uses this information to keep your global scope clean, and to reactively re-run cells.</p>
</div>mimetext/htmlrootassigneelast_run_timestampAdpersist_js_state·has_pluto_hook_features§cell_id$d5b9c438-b1e7-4417-870f-afdfc4ee7672depends_on_disabled_cells§runtime spublished_object_keysdepends_on_skipped_cells§errored$2717450b-8e9d-4be4-9156-53b2020a2e5dqueued¤logsrunning¦outputbody]Max 5 x + 3 y
Subject to
 con : x + 5 y ≤ 3.0
 x ≥ 0.0
 y ≥ 0.0
 x ≤ 1.0
 y ≤ 30.0
mimetext/plainrootassigneelast_run_timestampA0persist_js_state·has_pluto_hook_features§cell_id$2717450b-8e9d-4be4-9156-53b2020a2e5ddepends_on_disabled_cells§runtime8[published_object_keysdepends_on_skipped_cells§errored$946b13ae-65f2-4844-a38a-693b2f01bad4queued¤logsrunning¦outputbody0.4mimetext/plainrootassigneelast_run_timestampACxpersist_js_state·has_pluto_hook_features§cell_id$946b13ae-65f2-4844-a38a-693b2f01bad4depends_on_disabled_cells§runtimepublished_object_keysdepends_on_skipped_cells§errored$b99f3213-f2c4-4d85-b34c-a60052571af3queued¤logsrunning¦outputbody-<div class="markdown"><h1>Example</h1>
</div>mimetext/htmlrootassigneelast_run_timestampA[%persist_js_state·has_pluto_hook_features§cell_id$b99f3213-f2c4-4d85-b34c-a60052571af3depends_on_disabled_cells§runtime published_object_keysdepends_on_skipped_cells§errored$2e3d4b69-786e-4ccb-91ec-3b98f1f568e0queued¤logslinemsg[32m[1m  Activating[22m[39m new project at `/tmp/jl_1TF91H`
[32m[1m    Updating[22m[39m registry at `~/.julia/registries/General.toml`
[32m[1m   Resolving[22m[39m package versions...
[32m[1m   Installed[22m[39m CodecBzip2 ───────── v0.7.2
[32m[1m   Installed[22m[39m GLPK_jll ─────────── v5.0.0+0
[32m[1m   Installed[22m[39m JSONSchema ───────── v0.3.4
[32m[1m   Installed[22m[39m GLPK ─────────────── v0.14.14
[32m[1m   Installed[22m[39m MutableArithmetics ─ v0.2.22
[32m[1m   Installed[22m[39m JuMP ─────────────── v0.21.10
[32m[1m   Installed[22m[39m MathOptInterface ─── v0.9.22
[32m[1m    Updating[22m[39m `/tmp/jl_1TF91H/Project.toml`
 [90m [60bf3e95] [39m[92m+ GLPK v0.14.14[39m
 [90m [4076af6c] [39m[92m+ JuMP v0.21.10[39m
 [90m [7f904dfe] [39m[92m+ PlutoUI v0.7.64[39m
[32m[1m    Updating[22m[39m `/tmp/jl_1TF91H/Manifest.toml`
 [90m [6e696c72] [39m[92m+ AbstractPlutoDingetjes v1.3.2[39m
 [90m [6e4b80f9] [39m[92m+ BenchmarkTools v1.6.0[39m
 [90m [b99e7846] [39m[92m+ BinaryProvider v0.5.10[39m
 [90m [fa961155] [39m[92m+ CEnum v0.4.2[39m
 [90m [49dc2e85] [39m[92m+ Calculus v0.5.2[39m
 [90m [d360d2e6] [39m[92m+ ChainRulesCore v1.25.1[39m
 [90m [9e997f8a] [39m[92m+ ChangesOfVariables v0.1.10[39m
 [90m [523fee87] [39m[92m+ CodecBzip2 v0.7.2[39m
 [90m [944b1d66] [39m[92m+ CodecZlib v0.7.8[39m
 [90m [3da002f7] [39m[92m+ ColorTypes v0.12.1[39m
 [90m [bbf7d656] [39m[92m+ CommonSubexpressions v0.3.1[39m
 [90m [34da2185] [39m[92m+ Compat v4.16.0[39m
 [90m [864edb3b] [39m[92m+ DataStructures v0.18.22[39m
 [90m [163ba53b] [39m[92m+ DiffResults v1.1.0[39m
 [90m [b552c78f] [39m[92m+ DiffRules v1.15.1[39m
 [90m [ffbed154] [39m[92m+ DocStringExtensions v0.9.5[39m
 [90m [53c48c17] [39m[92m+ FixedPointNumbers v0.8.5[39m
 [90m [f6369f11] [39m[92m+ ForwardDiff v0.10.38[39m
 [90m [60bf3e95] [39m[92m+ GLPK v0.14.14[39m
 [90m [cd3eb016] [39m[92m+ HTTP v0.9.17[39m
 [90m [47d2ed2b] [39m[92m+ Hyperscript v0.0.5[39m
 [90m [ac1192a8] [39m[92m+ HypertextLiteral v0.9.5[39m
 [90m [b5f81e59] [39m[92m+ IOCapture v0.2.5[39m
 [90m [83e8ac13] [39m[92m+ IniFile v0.5.1[39m
 [90m [3587e190] [39m[92m+ InverseFunctions v0.1.17[39m
 [90m [92d709cd] [39m[92m+ IrrationalConstants v0.1.1[39m
 [90m [692b3bcd] [39m[92m+ JLLWrappers v1.7.0[39m
 [90m [682c06a0] [39m[92m+ JSON v0.21.4[39m
 [90m [7d188eb4] [39m[92m+ JSONSchema v0.3.4[39m
 [90m [4076af6c] [39m[92m+ JuMP v0.21.10[39m
 [90m [2ab3a3ac] [39m[92m+ LogExpFunctions v0.3.28[39m
 [90m [6c6e2e6c] [39m[92m+ MIMEs v1.1.0[39m
 [90m [1914dd2f] [39m[92m+ MacroTools v0.5.16[39m
 [90m [b8f27783] [39m[92m+ MathOptInterface v0.9.22[39m
 [90m [739be429] [39m[92m+ MbedTLS v1.1.9[39m
 [90m [d8a4904e] [39m[92m+ MutableArithmetics v0.2.22[39m
 [90m [77ba4419] [39m[92m+ NaNMath v0.3.7[39m
 [90m [bac558e1] [39m[92m+ OrderedCollections v1.8.1[39m
 [90m [69de0a69] [39m[92m+ Parsers v2.8.3[39m
 [90m [7f904dfe] [39m[92m+ PlutoUI v0.7.64[39m
 [90m [aea7be01] [39m[92m+ PrecompileTools v1.2.1[39m
 [90m [21216c6a] [39m[92m+ Preferences v1.4.3[39m
 [90m [189a3867] [39m[92m+ Reexport v1.2.2[39m
 [90m [276daf66] [39m[92m+ SpecialFunctions v1.8.8[39m
 [90m [90137ffa] [39m[92m+ StaticArrays v1.9.13[39m
 [90m [1e83bf80] [39m[92m+ StaticArraysCore v1.4.3[39m
 [90m [3bb67fe8] [39m[92m+ TranscodingStreams v0.9.13[39m
 [90m [410a4b4d] [39m[92m+ Tricks v0.1.10[39m
 [90m [5c2747f8] [39m[92m+ URIs v1.5.2[39m
 [90m [6e34b625] [39m[92m+ Bzip2_jll v1.0.9+0[39m
 [90m [e8aa6df9] [39m[92m+ GLPK_jll v5.0.0+0[39m
 [90m [efe28fd5] [39m[92m+ OpenSpecFun_jll v0.5.6+0[39m
 [90m [0dad84c5] [39m[92m+ ArgTools[39m
 [90m [56f22d72] [39m[92m+ Artifacts[39m
 [90m [2a0f44e3] [39m[92m+ Base64[39m
 [90m [ade2ca70] [39m[92m+ Dates[39m
 [90m [f43a241f] [39m[92m+ Downloads[39m
 [90m [7b1f6079] [39m[92m+ FileWatching[39m
 [90m [b77e0a4c] [39m[92m+ InteractiveUtils[39m
 [90m [b27032c2] [39m[92m+ LibCURL[39m
 [90m [76f85450] [39m[92m+ LibGit2[39m
 [90m [8f399da3] [39m[92m+ Libdl[39m
 [90m [37e2e46d] [39m[92m+ LinearAlgebra[39m
 [90m [56ddb016] [39m[92m+ Logging[39m
 [90m [d6f4376e] [39m[92m+ Markdown[39m
 [90m [a63ad114] [39m[92m+ Mmap[39m
 [90m [ca575930] [39m[92m+ NetworkOptions[39m
 [90m [44cfe95a] [39m[92m+ Pkg[39m
 [90m [de0858da] [39m[92m+ Printf[39m
 [90m [9abbd945] [39m[92m+ Profile[39m
 [90m [3fa0cd96] [39m[92m+ REPL[39m
 [90m [9a3f8284] [39m[92m+ Random[39m
 [90m [ea8e919c] [39m[92m+ SHA[39m
 [90m [9e88b42a] [39m[92m+ Serialization[39m
 [90m [6462fe0b] [39m[92m+ Sockets[39m
 [90m [2f01184e] [39m[92m+ SparseArrays[39m
 [90m [10745b16] [39m[92m+ Statistics[39m
 [90m [fa267f1f] [39m[92m+ TOML[39m
 [90m [a4e569a6] [39m[92m+ Tar[39m
 [90m [8dfed614] [39m[92m+ Test[39m
 [90m [cf7118a7] [39m[92m+ UUIDs[39m
 [90m [4ec0a83e] [39m[92m+ Unicode[39m
 [90m [e66e0078] [39m[92m+ CompilerSupportLibraries_jll[39m
 [90m [781609d7] [39m[92m+ GMP_jll[39m
 [90m [deac9b47] [39m[92m+ LibCURL_jll[39m
 [90m [29816b5a] [39m[92m+ LibSSH2_jll[39m
 [90m [c8ffd9c3] [39m[92m+ MbedTLS_jll[39m
 [90m [14a3606d] [39m[92m+ MozillaCACerts_jll[39m
 [90m [4536629a] [39m[92m+ OpenBLAS_jll[39m
 [90m [05823500] [39m[92m+ OpenLibm_jll[39m
 [90m [83775a58] [39m[92m+ Zlib_jll[39m
 [90m [8e850b90] [39m[92m+ libblastrampoline_jll[39m
 [90m [8e850ede] [39m[92m+ nghttp2_jll[39m
 [90m [3f19e933] [39m[92m+ p7zip_jll[39m
[32m[1m    Building[22m[39m GLPK → `~/.julia/scratchspaces/44cfe95a-1eb2-52ea-b672-e2afdf69b78f/833dbc8fbb0554e31186df509d67fc2f78f1bb09/build.log`
[32m[1mPrecompiling[22m[39m project...
[32m  ✓ [39m[90mGMP_jll[39m
[32m  ✓ [39m[90mCodecBzip2[39m
[32m  ✓ [39m[90mJSONSchema[39m
[32m  ✓ [39m[90mGLPK_jll[39m
[32m  ✓ [39m[90mMutableArithmetics[39m
[32m  ✓ [39m[90mMathOptInterface[39m
[32m  ✓ [39mGLPK
[32m  ✓ [39mJuMP
  8 dependencies successfully precompiled in 49 seconds (52 already precompiled)
text/plaincell_id$2e3d4b69-786e-4ccb-91ec-3b98f1f568e0kwargsidPlutoRunner_d1acb81efileP/home/runner/.julia/packages/Pluto/6smog/src/runner/PlutoRunner/src/io/stdout.jlgroupstdoutlevelLogLevel(-555)running¦outputbodymimetext/plainrootassigneelast_run_timestampAݰpersist_js_state·has_pluto_hook_features§cell_id$2e3d4b69-786e-4ccb-91ec-3b98f1f568e0depends_on_disabled_cells§runtime   &44published_object_keysdepends_on_skipped_cells§errored$15037686-c495-42c3-b976-11ac753dde18queued¤logsrunning¦outputbody1.0mimetext/plainrootassigneelast_run_timestampACǰpersist_js_state·has_pluto_hook_features§cell_id$15037686-c495-42c3-b976-11ac753dde18depends_on_disabled_cells§runtime^published_object_keysdepends_on_skipped_cells§errored$68e07edd-55dd-45d8-9f8a-24ae75a20960queued¤logsrunning¦outputbodya<bond def="xmax" unique_id="cI7pNeFaF6mJ"><input type='range' min='1' max='301' value='1'></bond>mimetext/htmlrootassigneelast_run_timestampApersist_js_state·has_pluto_hook_features§cell_id$68e07edd-55dd-45d8-9f8a-24ae75a20960depends_on_disabled_cells§runtimeʏ3published_object_keysdepends_on_skipped_cells§errored$267e9766-e2c1-4006-abb0-ae69fba94052queued¤logsrunning¦outputbody<div style="opacity: 0.5;"><div class="markdown"><h3>Part 2b: make definitions explicit for Pluto</h3>
<p>Alternatively, you can manually assign to the variable that is secretly defined to make Pluto understand.</p>
<p>⛔️ Don&#39;t:</p>
<pre><code class="language-julia">begin
	model &#61; Model&#40;GLPK.Optimizer&#41;

	@variable&#40;model, 20 &lt; y &lt; 30&#41;
	# global variable y is now defined, but Pluto does not know it

	...
end</code></pre>
<p>✔️ Do:</p>
<pre><code class="language-julia">begin
	model &#61; Model&#40;GLPK.Optimizer&#41;

	y &#61; @variable&#40;model, 20 &lt; y &lt; 30&#41;
	# global variable y is now defined, and Pluto knows it

	...
end</code></pre>
</div></div>mimetext/htmlrootassigneelast_run_timestampApersist_js_state·has_pluto_hook_features§cell_id$267e9766-e2c1-4006-abb0-ae69fba94052depends_on_disabled_cells§runtime򓶵published_object_keysdepends_on_skipped_cells§errored±cell_dependencies $e4d0ad7b-9e72-45c7-9eb9-0ed06567aef8precedence_heuristic	cell_id$e4d0ad7b-9e72-45c7-9eb9-0ed06567aef8downstream_cells_mapupstream_cells_mapmodel_opt$95e0721d-321f-478c-8d02-0ac070008a5bobjective_value$470eaa98-4073-11eb-349d-e9c34e5478c2precedence_heuristic	cell_id$470eaa98-4073-11eb-349d-e9c34e5478c2downstream_cells_mapmodel$2717450b-8e9d-4be4-9156-53b2020a2e5d$95e0721d-321f-478c-8d02-0ac070008a5bupstream_cells_map JuMP.MutableArithmetics.ZeroJuMP.add_variableGLPK$2e3d4b69-786e-4ccb-91ec-3b98f1f568e0JuMP._functionizeJuMP.VariableInfo JuMP.MutableArithmetics.operate!Model#JuMP._throw_error_for_invalid_senseJuMP.set_objective@variableJuMP$2e3d4b69-786e-4ccb-91ec-3b98f1f568e0JuMP.add_constraintJuMP.build_variableJuMP._valid_modelJuMP.build_constraintxmax$68e07edd-55dd-45d8-9f8a-24ae75a20960@objectiveJuMP._error_if_cannot_register@constraint$9b4e18a3-669f-4bab-8c22-565428ebf299precedence_heuristic	cell_id$9b4e18a3-669f-4bab-8c22-565428ebf299downstream_cells_mapopacity$267e9766-e2c1-4006-abb0-ae69fba94052upstream_cells_map$cdda279d-60bf-495c-b796-a62e5dd1d699precedence_heuristic	cell_id$cdda279d-60bf-495c-b796-a62e5dd1d699downstream_cells_mapopacity$267e9766-e2c1-4006-abb0-ae69fba94052upstream_cells_mapBaseHTML@MIME_strrepr$8bc3d43a-1460-498b-baa8-fcb9a3338457precedence_heuristic	cell_id$8bc3d43a-1460-498b-baa8-fcb9a3338457downstream_cells_mapupstream_cells_map@md_strgetindex$ce6d95f3-d745-4215-844c-727c9d90861dprecedence_heuristic	cell_id$ce6d95f3-d745-4215-844c-727c9d90861ddownstream_cells_mapupstream_cells_map@md_strgetindex$759c0a90-bb03-456e-bbf6-8bf80b249c07precedence_heuristic	cell_id$759c0a90-bb03-456e-bbf6-8bf80b249c07downstream_cells_mapupstream_cells_map@md_strgetindex$69a565bc-e250-4105-9b6b-3b9879dcb417precedence_heuristic	cell_id$69a565bc-e250-4105-9b6b-3b9879dcb417downstream_cells_mapupstream_cells_mapmodel_opt$95e0721d-321f-478c-8d02-0ac070008a5btermination_status$95e0721d-321f-478c-8d02-0ac070008a5bprecedence_heuristic	cell_id$95e0721d-321f-478c-8d02-0ac070008a5bdownstream_cells_mapmodel_opt$69a565bc-e250-4105-9b6b-3b9879dcb417$e4d0ad7b-9e72-45c7-9eb9-0ed06567aef8$15037686-c495-42c3-b976-11ac753dde18$946b13ae-65f2-4844-a38a-693b2f01bad4upstream_cells_mapoptimize!model$470eaa98-4073-11eb-349d-e9c34e5478c2$d5b9c438-b1e7-4417-870f-afdfc4ee7672precedence_heuristic	cell_id$d5b9c438-b1e7-4417-870f-afdfc4ee7672downstream_cells_mapupstream_cells_map@md_strgetindex$2717450b-8e9d-4be4-9156-53b2020a2e5dprecedence_heuristic	cell_id$2717450b-8e9d-4be4-9156-53b2020a2e5ddownstream_cells_mapupstream_cells_mapmodel$470eaa98-4073-11eb-349d-e9c34e5478c2Text$946b13ae-65f2-4844-a38a-693b2f01bad4precedence_heuristic	cell_id$946b13ae-65f2-4844-a38a-693b2f01bad4downstream_cells_mapupstream_cells_mapmodel_opt$95e0721d-321f-478c-8d02-0ac070008a5bvalue$b99f3213-f2c4-4d85-b34c-a60052571af3precedence_heuristic	cell_id$b99f3213-f2c4-4d85-b34c-a60052571af3downstream_cells_mapupstream_cells_map@md_strgetindex$2e3d4b69-786e-4ccb-91ec-3b98f1f568e0precedence_heuristiccell_id$2e3d4b69-786e-4ccb-91ec-3b98f1f568e0downstream_cells_mapPkg$2e3d4b69-786e-4ccb-91ec-3b98f1f568e0GLPK$470eaa98-4073-11eb-349d-e9c34e5478c2PlutoUIJuMP$470eaa98-4073-11eb-349d-e9c34e5478c2upstream_cells_mapPkg.addPkg$2e3d4b69-786e-4ccb-91ec-3b98f1f568e0Pkg.activatePkg.PackageSpecmktempdir$15037686-c495-42c3-b976-11ac753dde18precedence_heuristic	cell_id$15037686-c495-42c3-b976-11ac753dde18downstream_cells_mapupstream_cells_mapmodel_opt$95e0721d-321f-478c-8d02-0ac070008a5bvalue$68e07edd-55dd-45d8-9f8a-24ae75a20960precedence_heuristic	cell_id$68e07edd-55dd-45d8-9f8a-24ae75a20960downstream_cells_mapxmax$470eaa98-4073-11eb-349d-e9c34e5478c2upstream_cells_mapCoreBase:PlutoRunner.create_bondPlutoRunnerCore.applicable@bindBase.getSlider$267e9766-e2c1-4006-abb0-ae69fba94052precedence_heuristic	cell_id$267e9766-e2c1-4006-abb0-ae69fba94052downstream_cells_mapupstream_cells_map@md_str|>opacity$cdda279d-60bf-495c-b796-a62e5dd1d699$9b4e18a3-669f-4bab-8c22-565428ebf299getindexcell_execution_order $2e3d4b69-786e-4ccb-91ec-3b98f1f568e0$d5b9c438-b1e7-4417-870f-afdfc4ee7672$759c0a90-bb03-456e-bbf6-8bf80b249c07$ce6d95f3-d745-4215-844c-727c9d90861d$8bc3d43a-1460-498b-baa8-fcb9a3338457$cdda279d-60bf-495c-b796-a62e5dd1d699$9b4e18a3-669f-4bab-8c22-565428ebf299$267e9766-e2c1-4006-abb0-ae69fba94052$b99f3213-f2c4-4d85-b34c-a60052571af3$68e07edd-55dd-45d8-9f8a-24ae75a20960$470eaa98-4073-11eb-349d-e9c34e5478c2$2717450b-8e9d-4be4-9156-53b2020a2e5d$95e0721d-321f-478c-8d02-0ac070008a5b$69a565bc-e250-4105-9b6b-3b9879dcb417$e4d0ad7b-9e72-45c7-9eb9-0ed06567aef8$15037686-c495-42c3-b976-11ac753dde18$946b13ae-65f2-4844-a38a-693b2f01bad4last_hot_reload_time        shortpathjump inside Pluto.jlprocess_statusreadypathJ/home/runner/work/disorganised-mess/disorganised-mess/jump inside Pluto.jlpluto_versionv0.19.47last_save_timeApTcell_order $2e3d4b69-786e-4ccb-91ec-3b98f1f568e0$d5b9c438-b1e7-4417-870f-afdfc4ee7672$759c0a90-bb03-456e-bbf6-8bf80b249c07$ce6d95f3-d745-4215-844c-727c9d90861d$8bc3d43a-1460-498b-baa8-fcb9a3338457$267e9766-e2c1-4006-abb0-ae69fba94052$cdda279d-60bf-495c-b796-a62e5dd1d699$9b4e18a3-669f-4bab-8c22-565428ebf299$b99f3213-f2c4-4d85-b34c-a60052571af3$470eaa98-4073-11eb-349d-e9c34e5478c2$2717450b-8e9d-4be4-9156-53b2020a2e5d$95e0721d-321f-478c-8d02-0ac070008a5b$68e07edd-55dd-45d8-9f8a-24ae75a20960$69a565bc-e250-4105-9b6b-3b9879dcb417$e4d0ad7b-9e72-45c7-9eb9-0ed06567aef8$15037686-c495-42c3-b976-11ac753dde18$946b13ae-65f2-4844-a38a-693b2f01bad4published_objectsnbpkginstall_time_nsinstantiatedòinstalled_versionsterminal_outputsenabled·restart_recommended_msgrestart_required_msgbusy_packageswaiting_for_permission,waiting_for_permission_but_probably_disabled«cell_inputs $e4d0ad7b-9e72-45c7-9eb9-0ed06567aef8cell_id$e4d0ad7b-9e72-45c7-9eb9-0ed06567aef8codeobjective_value(model_opt)metadatashow_logsèdisabled®skip_as_script«code_folded$470eaa98-4073-11eb-349d-e9c34e5478c2cell_id$470eaa98-4073-11eb-349d-e9c34e5478c2codelet
	global model = Model(GLPK.Optimizer)
	
	@variable(model, 0 <= x <= xmax)
	@variable(model, 0 <= y <= 30)
	
	@objective(model, Max, 5x + 3 * y)
	
	@constraint(model, con, 1x + 5y <= 3)
	
	model
endmetadatashow_logsèdisabled®skip_as_script«code_folded$9b4e18a3-669f-4bab-8c22-565428ebf299cell_id$9b4e18a3-669f-4bab-8c22-565428ebf299code!opacity(op) = x -> opacity(x, op)metadatashow_logsèdisabled®skip_as_script«code_folded$cdda279d-60bf-495c-b796-a62e5dd1d699cell_id$cdda279d-60bf-495c-b796-a62e5dd1d699code]opacity(x, op) = HTML("""<div style="opacity: $(op);">$(repr(MIME"text/html"(), x))</div>""")metadatashow_logsèdisabled®skip_as_script«code_folded$8bc3d43a-1460-498b-baa8-fcb9a3338457cell_id$8bc3d43a-1460-498b-baa8-fcb9a3338457codeٹmd"""
To access variables from the model that are hidden by a let block, use the alternative syntax:


⛔️ Don't:
```julia
value(y)
```

✔️ Do:
```julia
value(model[:y])
```

"""metadatashow_logsèdisabled®skip_as_script«code_folded$ce6d95f3-d745-4215-844c-727c9d90861dcell_id$ce6d95f3-d745-4215-844c-727c9d90861dcodeJmd"""
## Part 2: secret definitions

JuMP's macros create global variables, which are not seen by Pluto. For example, `@variable(model, 0 < x < 1)` defines a global variable called `x`, while Pluto thinks that the global variable `x` was *referenced*, not assigned.

There are two ways to solve this.

### Part 2a: `let` block (recommended)
Place the macros inside a `let` block, to locally scope any secretly created variables.

⛔️ Don't:
```julia
begin
	model = Model(GLPK.Optimizer)

	@variable(model, 20 < y < 30)
	# global variable y is now defined, but Pluto does not know it

	...
end
```

✔️ Do:
```julia
let
	global model = Model(GLPK.Optimizer)

	@variable(model, 20 < y < 30)
	# locally scoped variable y is now defined. Pluto does not know about it, but since the global scope is unaffected, this is fine

	...
end
```
"""metadatashow_logsèdisabled®skip_as_script«code_folded$759c0a90-bb03-456e-bbf6-8bf80b249c07cell_id$759c0a90-bb03-456e-bbf6-8bf80b249c07codemd"""
## Part 1: model mutations

Because JuMP's macros _modify_ a model, it is important the the **model construction is contained in a single cell**. Use a `let` block (more in Part 2).

⛔️ Don't:
```julia
model = Model(GLPK.Optimizer)
```
```julia
@variable(model, 20 < y < 30)
```

✔️ Do:
```julia
let
	global model = Model(GLPK.Optimizer)

	@variable(model, 20 < y < 30)

	...
end
```

#### optimize!

Similarly, `optimize!` will _modify_ the model, so I recommend calling it in the same cell as the model construction.

If, for the purpose of a narrative, you need the optimization to happen in a different cell, then use a "new state, new name" trick:

```julia
begin
	optimize!(model)
	model_optimized = model
end
```

In other cells, reference `model_optimized` to access `model` to guarantee that the model optimization has already happened:

```julia
# in other cells
value(model_optimized[:x])
```
	

"""metadatashow_logsèdisabled®skip_as_script«code_folded$69a565bc-e250-4105-9b6b-3b9879dcb417cell_id$69a565bc-e250-4105-9b6b-3b9879dcb417codetermination_status(model_opt)metadatashow_logsèdisabled®skip_as_script«code_folded$95e0721d-321f-478c-8d02-0ac070008a5bcell_id$95e0721d-321f-478c-8d02-0ac070008a5bcode,model_opt = let
	optimize!(model)
	model
endmetadatashow_logsèdisabled®skip_as_script«code_folded$d5b9c438-b1e7-4417-870f-afdfc4ee7672cell_id$d5b9c438-b1e7-4417-870f-afdfc4ee7672codemd"""
# How to use JuMP in Pluto?

JuMP uses macros to form a domain-specific language. That is very cool! but unfortunately, Pluto has trouble understanding code with macros. This is a difficult problem that we currently working on, and it is getting closer to being fixed!

For any cell, it is important that Pluto correctly understands which variables are **referenced** and which are **defined**. Pluto's runtime uses this information to keep your global scope clean, and to reactively re-run cells.
"""metadatashow_logsèdisabled®skip_as_script«code_folded$2717450b-8e9d-4be4-9156-53b2020a2e5dcell_id$2717450b-8e9d-4be4-9156-53b2020a2e5dcodeText(model)metadatashow_logsèdisabled®skip_as_script«code_folded$946b13ae-65f2-4844-a38a-693b2f01bad4cell_id$946b13ae-65f2-4844-a38a-693b2f01bad4codevalue(model_opt[:y])metadatashow_logsèdisabled®skip_as_script«code_folded$b99f3213-f2c4-4d85-b34c-a60052571af3cell_id$b99f3213-f2c4-4d85-b34c-a60052571af3codemd"""
# Example
"""metadatashow_logsèdisabled®skip_as_script«code_folded$2e3d4b69-786e-4ccb-91ec-3b98f1f568e0cell_id$2e3d4b69-786e-4ccb-91ec-3b98f1f568e0codebegin
    import Pkg
    Pkg.activate(mktempdir())
    Pkg.add([
        Pkg.PackageSpec(name="JuMP", version="0.21"),
        Pkg.PackageSpec(name="GLPK", version="0.14"),
        Pkg.PackageSpec(name="PlutoUI", version="0.7"),
    ])
    using JuMP, GLPK, PlutoUI
endmetadatashow_logsèdisabled®skip_as_script«code_folded$15037686-c495-42c3-b976-11ac753dde18cell_id$15037686-c495-42c3-b976-11ac753dde18codevalue(model_opt[:x])metadatashow_logsèdisabled®skip_as_script«code_folded$68e07edd-55dd-45d8-9f8a-24ae75a20960cell_id$68e07edd-55dd-45d8-9f8a-24ae75a20960code@bind xmax Slider(1:.01:4)metadatashow_logsèdisabled®skip_as_script«code_folded$267e9766-e2c1-4006-abb0-ae69fba94052cell_id$267e9766-e2c1-4006-abb0-ae69fba94052codemd"""
### Part 2b: make definitions explicit for Pluto

Alternatively, you can manually assign to the variable that is secretly defined to make Pluto understand.

⛔️ Don't:
```julia
begin
	model = Model(GLPK.Optimizer)

	@variable(model, 20 < y < 30)
	# global variable y is now defined, but Pluto does not know it

	...
end
```

✔️ Do:
```julia
begin
	model = Model(GLPK.Optimizer)

	y = @variable(model, 20 < y < 30)
	# global variable y is now defined, and Pluto knows it

	...
end
```

""" |> opacity(.5)metadatashow_logsèdisabled®skip_as_script«code_foldedënotebook_id$b47c0b74-4aa4-11f0-1152-8f4584eee5fbin_temp_dir¨metadata